import http from './http'

export interface Certificate {
  id: number
  userId: number
  userName: string
  courseId: number
  courseName: string
  certificateNumber: string
  certificateName: string
  issueDate: string
  completionRate: number
  finalScore?: number
  verificationCode: string
  templateType: 'BASIC' | 'ADVANCED' | 'PROFESSIONAL'
  status: 'ACTIVE' | 'REVOKED'
  pdfUrl?: string
  issuedBy?: number
  issuerName?: string
  createdAt: string
  updatedAt: string
}

export const certificateApi = {
  // 获取证书详情
  get: (id: number) => 
    http.get<Certificate>(`/v1/certificates/${id}`),

  // 获取我的证书列表
  getMy: (params?: {
    page?: number
    pageSize?: number
  }) => 
    http.get<{ content: Certificate[], totalElements: number }>('/v1/certificates/my', { params }),

  // 验证证书
  validate: (certificateNumber: string, verificationCode: string) => 
    http.get<Certificate>('/v1/certificates/validate', { 
      params: { certificateNumber, verificationCode } 
    }),

  // 撤销证书（管理员）
  revoke: (id: number) => 
    http.post(`/v1/certificates/${id}/revoke`)
}